package com.cy.controller;


import com.cy.bfzcommons.pojo.Rights;
import com.cy.bfzcommons.service.RightsService;
import com.cy.bfzcommons.web.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rights")
@CrossOrigin

public class RightsController {
    @Autowired
    private RightsService rightsService;


    @GetMapping
    public JsonResult getRights(){
        List<Rights> list = rightsService.getRights();
        return JsonResult.ok(list);
    }


    @GetMapping("/selectFind")
    public  JsonResult getSelectFind(@ApiParam(name="level",value="权限等级",required=true)Integer level){
        List<Rights> list = rightsService.selectFind(level);
        return JsonResult.ok(list);
    }


    @PostMapping()
    public  JsonResult insertRights(@ApiParam(name="rights",value="权限信息",required=true)@RequestBody Rights rights ){

        System.out.println(rights);
        String s = rightsService.insertRights(rights);
        return  JsonResult.ok(s);
    }


    @PutMapping
    public JsonResult updateRights(@ApiParam(name="rights",value="权限信息",required=true)@RequestBody Rights rights){
        String success  = rightsService.updateRights(rights);
        return JsonResult.ok(success);
    }


    @DeleteMapping("/{id}/{level}")
    public JsonResult deleteById(@ApiParam(name="id",value="权限id",required=true)@PathVariable Integer id,
                                 @ApiParam(name="level",value="权限等级",required=true)@PathVariable Integer level){
        rightsService.deleteById(id,level);
        return  JsonResult.ok();
    }


    @GetMapping("/selectByName/{username}")
    public JsonResult selectByName(@ApiParam(name="username",value="管理员名",required=true) @PathVariable String username){
        List<Rights> list = rightsService.selectRightsByName(username);
        return JsonResult.ok(list);
    }
   // @GetMapping
   // public JsonResult getById
}
